//
//  MyCell_1.m
//  UI09_4_Cell 高度自动调整
//
//  Created by Scott on 15/5/8.
//  Copyright (c) 2015年 www.lanou3g.com 蓝欧3G. All rights reserved.
//

#import "MyCell_1.h"

@implementation MyCell_1

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.cellLable = [[UILabel alloc] init];
        self.cellLable.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:self.cellLable];
        [_cellLable release];
    }
    return  self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.cellLable.frame = self.contentView.frame;
    self.cellLable.numberOfLines = 0;
    [self.cellLable sizeToFit];
    
}

#pragma mark - 计算文本框高度的类方法
+ (CGFloat)heightWithText:(NSString *)text
{
    /**
     * The UIKit framework adds methods to NSString to support the drawing of strings and to compute the bounding box of a string prior to drawing
     *
     * @ method
            - boundingRectWithSize:options:attributes:context:
     */
    
    /**
     * @brief   返回值类型为CGRect类型.
     * @param   绘制矩形大小用来放文字. 高度如果为0, 没有限制
     * 
     * @param   枚举(NSStringDrawingUsesLineFragmentOrigin)
     *
     * @param   属性数组(一般设置字体和字体大小属性)
     *
     * @param   nil即可
     */
    CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
    
    CGRect rect = [text boundingRectWithSize:CGSizeMake(screenWidth, 0) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]} context:nil];
    
    /* 返回矩形的高度 */
    return rect.size.height;
    
}






- (void)dealloc
{
    [_cellLable release];
    [super dealloc];
}






- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
